* add.prg 03/15/83 
* this program will add records to the current files 
* the records will be marked as new 
* for later verification and merging 

* eliminate use of indexes for speed
SET INDEX to

* set up screen for data entry 
SET FORMAT TO mod-rec 

*loop until finished adding records 
STORE t TO more 
DO WHILE more 
  
  * get a new set of memory variables for data entry 
  RESTORE FROM ADD 
  STORE 'Add new records' TO mode 
  STORE 'Enter as many records as you want.' TO prompt1 
  STORE 'When done, enter blank for Last name and Company' TO prompt2
  STORE 'Or Control Q to end session' TO prompt3 
  STORE t TO more 
  
  * let user enter data 
  READ 
  
  * if a last name or company was entered 
  * add a new record with the entered data 
  IF mlastname <> ' ' .OR. mcompany1 <> ' ' 
    
    * validate entries 
    DO valid.acg 
    
    * add a new record to the files 
    APPEND BLANK 
    
    * fill in the new data 
    REPLACE lastname WITH mlastname, fname WITH mfname 
    REPLACE spouse WITH mspouse, mr WITH mmr 
    REPLACE title WITH mtitle, company1 WITH mcompany1 
    REPLACE company2 WITH mcompany2, caddress WITH mcaddress 
    REPLACE suite WITH msuite, ccity WITH mccity
    REPLACE cst WITH mcst, czip WITH mczip 
    REPLACE address WITH maddress, apt WITH mapt
    REPLACE city WITH mcity, st WITH mst
    REPLACE zip WITH mzip, ophone WITH mophone
    REPLACE phone WITH mphone, dear WITH mdear 
    REPLACE send WITH msend, misc WITH mmisc 
    REPLACE cs1 WITH mcs1, cs2 WITH mcs2 
    REPLACE cs3 WITH mcs3, cs4 WITH mcs4 
    REPLACE cs5 WITH mcs5, cs6 WITH mcs6 
    REPLACE UPDATE WITH mupdate 
    
    * mark the record as new
    REPLACE new WITH t
    
    
  ELSE
    * there are no more records to add
    * set up the loop to finish
    
    * restore original index and reindex
    * since it takes time, first tell them
    ERASE
    ?
    ?
    ?
    ? 'Files are now being reindexed. ' 
    ? 'Please be patient as this will take a few minutes.' 
    ?
    
    INDEX ON !(lastname) TO lastname
    INDEX ON !(company1) TO company
    INDEX ON zip TO zip
    SET INDEX to lastname, company, zip
    STORE f TO more

  ENDIF mlastname <> ' ' .OR. mcompany1 <> ' '  
  
  *loop back again
ENDDO WHILE more  

*release local variables
RELEASE ALL

* restore original variables
STORE '?' TO command

